//
//  XYTUserInfoUploadCell.m
//  XYTPayOrderSystem
//
//  Created by wupeng on 2017/8/30.
//  Copyright © 2017年 wupeng. All rights reserved.
//

#import "XYTUserInfoUploadCell.h"

@interface XYTUserInfoUploadCell ()<UITextFieldDelegate>

@end

@implementation XYTUserInfoUploadCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 2.5, 80, 35)];
    titleLab.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:titleLab];
    self.titleLab = titleLab;
    
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(titleLab.frame)+5, 2.5, kScreen_Width-20-80-5-30, 35)];
    textField.textAlignment = NSTextAlignmentLeft;
    textField.borderStyle = UITextBorderStyleLine;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.font = [UIFont systemFontOfSize:14];
    textField.delegate = self;
    [self.contentView addSubview:textField];
    self.textField = textField;
    
}

- (void)setStarTitle:(NSString *)title{
    NSRange range = [title rangeOfString:@"*"];
    if (title.length >0 &&range.location != NSNotFound) {
        NSMutableAttributedString * attStr = [[NSMutableAttributedString alloc] initWithString:title];
        NSRange range = [title rangeOfString:@"*"];
        [attStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
        [self.titleLab setAttributedText:attStr];
        return;
    }
    self.titleLab.text = title;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    if (textField.text.length>0) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"UserInfoUploadCell_textField" object:nil userInfo:@{self.titleLab.text:textField.text}];
    }
    return YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
